package com.example.a16478082;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

public class MyAdapter extends BaseAdapter {
    List<HashMap<String,Object>> myData;
    Context context;
    LayoutInflater layoutInflater;
    public MyAdapter(List<HashMap<String,Object>>myData){
        this.myData=myData;
        this.context=context;
    }



    @Override
    public int getCount() {
        return myData.size();
    }

    @Override
    public Object getItem(int i) {
        return myData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
//        动态布局加载器
        layoutInflater=LayoutInflater.from(context);
        View itemView=layoutInflater.inflate(R.layout.my_listitem,null);
        TextView tv_name=itemView.findViewById(R.id.ItemTitle);
        TextView tv_info=itemView.findViewById(R.id.ItemPrice);
        ImageView image_photo=itemView.findViewById(R.id.photo);
//        适配数据
        tv_name.setText((String) myData.get(i).get("name"));
        tv_info.setText((String) myData.get(i).get("info"));
        image_photo.setImageResource(R.mipmap.ic_launcher);
//        搞事情
        if(i==2){
            tv_name.setTextColor(Color.GRAY);
        }
        return itemView;
    }
}
